<template>
  <div>
    <el-form ref="configform" :model="configData" label-width="240px">
      <el-form-item label="允许大比例优惠(超过50%)">
        <el-switch v-model="configData.is_large_scale" active-color="#13ce66" active-value="1" inactive-value="0"></el-switch>
      </el-form-item>
      <el-form-item label="优惠券最高发放数量(不超过10万)">
        <el-input v-model="configData.number" placeholder="请输入" size="small" style="max-width:70%"></el-input>
      </el-form-item>
    </el-form>

    <div style="text-align:center">
      <el-button type="primary" size="small" style="padding:8px 30px;" @click="submit">提 交</el-button>
    </div>
  </div>
</template>

<script>
import { getcouponConfig, putcouponConfig } from '@/api/marketing'

export default {
  name: 'CouponConfig',
  data() {
    return {
      configData: { is_large_scale: '1', number: '' },
    }
  },
  mounted() {
    this.getCouponConfig();
  },
  methods: {
    getCouponConfig() {
      getcouponConfig({key: this.$store.state.app.activeApp.saa_key}).then(res => {
        if(res.status === 200) {
          this.configData = res.data;
        }else{
          this.$message.error(res.message);
        }
      })
    },
    submit() {
      const params = {
        key: this.$store.state.app.activeApp.saa_key,
        ...this.configData
      }
      putcouponConfig(params).then(res => {
        if(res.status === 200) {
          this.$emit('success');
          this.$message.success('修改成功！');
        }else{
          this.$message.error(res.message);
        }
      })
    }
  },
}
</script>